package com.itcz.web.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 阿里云对象存储客户端
 *
 * @author <a href="https://github.com/liyupi">奥数定理</a>
 * @from <a href="https://blog.csdn.net/qq_63143493?spm=1000.2115.3001.5343">个人博客</a>
 */
@Configuration
@ConfigurationProperties(prefix = "aliyun.oss")
@Data
public class OssClientConfig {
    /**
     * 区域
     */
    private String endpoint;

    /**
     * 访问密钥Id
     */
    private String accessKeyId;

    /**
     * 访问密钥
     */
    private String accessKeySecret;

    /**
     * 桶名
     */
    private String bucketName;

    @Bean
    public OSS ossClient() {
        // 初始化阿里云对象存储客服端
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }
}